let BallControl =require("BallControl");


//物理系统
let physicsManager = cc.director.getPhysicsManager();
physicsManager.enabled = true;
// physicsManager.debugDrawFlags =
//     // 0;
//     // cc.PhysicsManager.DrawBits.e_aabbBit |
//     cc.PhysicsManager.DrawBits.e_jointBit |
//     cc.PhysicsManager.DrawBits.e_shapeBit
//     ;


    
let GameCtl = cc.Class({
    //cc.Class({
    extends: cc.Component,

    properties:()=>(
        {
            scoreCtl:{
                default:null,
                type:require("ScoreControl"),
            },
            ballCtl:{
                default:null,
                type:require("BallManager"),
            },
            BarCtl:{
              default:null,
              type:require("BarControl"),
            },

            Spawner:{
                default:null,
                type:require("CollisionSpawner"),
            },

            uiCtl:{
                default:null,
                type:require("UIManager"),
            },

            _isPlaying:{
                default:false,
            },


        }
    ),


    statics:{
        instance:null,
    },


     onLoad () {

        //cc.error("gameCtl onload");
        //单例
        GameCtl.instance =this;



         //开启碰撞系统
         let collisionManager =cc.director.getCollisionManager();
         collisionManager.enabled =true;
         //collisionManager.enabledDebugDraw =true;

         //console.log("开启碰撞系统");


         this.scoreCtl= this.node.getComponentInChildren(require("ScoreControl"));
        //组件
        //this.scoreCtl =this.node.getco
     },

    start () {




    },

    StartGame(){




        this.Spawner.StartGame();
        this.ballCtl.StartGame();
        //this.uiCtl.StartGame();
        this._isPlaying =true;
    },

    //重置游戏
    RestGame()
    {
       this.scoreCtl.RestGame();

    },

    GameOver()
    {
        this._isPlaying =false;

        this.uiCtl.GameOver();
        this.ballCtl.GameOver();

        this.Spawner.GameOver();



    },

     update (dt) {

        if(this._isPlaying)
        {
            if(this.ballCtl.CheckPos()===false)
            {
                //cc.log("GameOver");
                this.GameOver();
            }

        }
     },
});
//module.exports =GameCtl;